package aaaBlogger.img;

import org.openqa.selenium.By;
import org.openqa.selenium.ElementNotVisibleException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
 





import com.attilax.cmsPoster.BlogPubberMainform;
import com.attilax.cmsPoster.Ipub;
import com.attilax.formH5.EncodeX;
import com.attilax.io.filex;
import com.attilax.io.pathx;
import com.attilax.secury.aes;
import com.attilax.util.PropX;


/**
 * aaaBlogger.CnblogsPubber
 * @author Administrator
 *
 */
public class CsdnPubber  implements Ipub{

	@Override
	public void pub2(String p1tit, String p2_txt, FirefoxDriver driver) {
		
	
		try {
			new Select(driver.findElement(By.id("selType")))
			.selectByVisibleText("原创");
		} catch (Exception e) {
			// TODO: handle exception
		}
	
		// driver.findElement(By.cssSelector("option[value=\"1\"]")).click();

		driver.findElement(By.id("txtTitle")).clear();
		driver.findElement(By.id("txtTitle")).sendKeys(p1tit);
		try {
			driver.findElement(By.id("editor")).sendKeys(p2_txt);
			// driver.findElement(By.id("editor")).
		} catch (ElementNotVisibleException e) {
			// (IJavaScriptExecutor)
			JavascriptExecutor jse = (JavascriptExecutor) driver;
			p2_txt = EncodeX.jsEncodeSingleQuoue(p2_txt);
			// p2_txt="test in html";
			String baseDir=pathx.classPathParent_jensyegeor()
					 + "/blogger";
			String js =filex.read(baseDir + "/db/" + BlogPubberMainform.blogName.get()
					 
					+ "/editor__form.js");
			String script = js.replace("@txt", p2_txt);

			// window.document.getElementById('editor').value='..xxx'
			driver.executeScript(script,
					driver.findElement(By.id("editor")));
			// jse.ex
		}

		driver.findElement(By.id("chk_tag_")).click();
		driver.findElement(By.id("radChl3")).click();
		
		try {
			driver.findElement(By.id("chk_tag_19")).click();
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		
		driver.findElement(By.id("chkHome")).click();
		driver.findElement(By.id("txtCheckCode")).click();
		driver.findElement(By.id("txtCheckCode")).clear();
		driver.findElement(By.id("txtCheckCode")).sendKeys("12");
		
	}

	@Override
	public void login(FirefoxDriver driver, Object  px2) {
		PropX px=(PropX) px2;
		driver.findElement(By.id("username")).clear();
		driver.findElement(By.id("username")).sendKeys("attilax");
		driver.findElement(By.id("password")).clear();
		String pwd_enced=px.getProperty("pwd").trim();
		 
		String pwd =aes.decrypt(pwd_enced, "iluvmole");
		driver.findElement(By.id("password")).sendKeys(pwd);
		driver.findElement(By.id("rememberMe")).click();
		//
		try {
			driver.findElement(By.linkText("登录")).click();
		} catch (NoSuchElementException e) {
			driver.findElement(By.cssSelector("input.logging")).click();
		}

		
	}

}
